#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

package=libjpeg

export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

include debian/patch.mk

export CFLAGS=-D_REENTRANT -g -Wall
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif


DH_COMPAT=1
#export DH_VERBOSE=1

build: build-stamp 
build-stamp: patch-stamp
	dh_testdir
	./configure --prefix=/usr --mandir=usr/share/man \
	 --enable-static --enable-shared --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE)
	printf '#!/bin/sh\nexec libtool "$$@"\n' >libtool
	$(MAKE)
	sh debian/check-jpeg
	$(MAKE) -C debian/extra

	touch build-stamp

clean: patch
	dh_testdir
	dh_testroot
	-rm -f build-stamp
	-$(MAKE) clean
	-$(MAKE) clean -C debian/extra
	-rm -f libtool libtool.cfg Makefile jconfig.h config.log
	-rm -rf testjpg
	dh_clean

binary-indep: 

binary-arch: build
	dh_testdir 
	dh_testroot 
	dh_clean -k
	dh_installdirs 
	$(MAKE) install \
		prefix=`pwd`/debian/tmp/usr \
		mandir=`pwd`/debian/tmp/usr/share/man/man1
	$(MAKE) install -C debian/extra prefix=`pwd`/debian/tmp/usr
#<ballombe@debian.org>:mjpegtools require this file to build and header say:
# * These declarations are considered internal to the JPEG library; most
# * applications using the library shouldn't need to include this file.
# So it is not forbidden to use it, therefore it must be installed.
	install -m644 jpegint.h debian/tmp/usr/include
	# fix jconfig.h 
	rm debian/tmp/usr/include/jconfig.h
	sed -e "s/#\(undef\|define\) HAVE_STD\(DEF\|LIB\)_H//g" \
		jconfig.h > debian/tmp/usr/include/jconfig.h
	# separate out lib package
	dh_movefiles
	# Remove empty dirs
	rmdir debian/tmp/usr/share/man/man1 debian/tmp/usr/share/man
	rmdir debian/tmp/usr/bin debian/tmp/usr/include debian/tmp/usr/share
	# Finish it off with debhelper
	dh_installdocs README
	dh_installexamples 
#	dh_installmanpages 
	dh_installchangelogs change.log
	dh_strip 
	dh_compress 
	dh_fixperms 
	dh_installdeb 
	dh_shlibdeps -l`pwd`/debian/tmp/usr/lib 
	dh_gencontrol 
#	dh_makeshlibs
	dh_md5sums 
	dh_builddeb 

binary:	binary-indep binary-arch

.PHONY: clean binary-indep binary-arch binary build patch
